#define  _CRT_SECURE_NO_WARNINGS

#include <iostream>
using namespace std;
#include <unordered_set>
#include <unordered_map>

#include "hash_table.h"
#include "my_unordered_map.h"
#include "my_unordered_set.h"


//template <class Container>
//void Print(const Container& con)
//{
//	for (auto& e : con)
//	{
//		cout << e<< endl;
//	}
//	cout << endl;
//}



//Key 修改问题 , set , key不支持修改
void Test01()
{

	GJG::unordered_set<int> s;
	//unordered_set<int> s;
	s.insert(1);
	s.insert(1);
	s.insert(1);
	s.insert(2);
	s.insert(3);
	s.insert(4);

	//测试普通迭代器
	auto it = s.begin();
	while (it != s.end())
	{
		// 
		//*it = 2;
		cout << *it << endl;
		++it;
	}
	cout << endl;
}

//map 中修改是允许 value 修改 ,key 依旧不能改
void Test02()
{

	GJG::unordered_map<int, int> s;
	//unordered_map<int, int> s;

	s.insert({ 1,1 });
	s.insert({ 1,1 });
	s.insert({ 1,1 });
	s.insert({ 2,2 });
	s.insert({ 3,3 });
	s.insert({ 4,4 });

	//测试普通迭代器
	auto it = s.begin();
	while (it != s.end())
	{
		//it->first = 2;
		it->second = 2;
		cout << it->first << ":" << it->second << endl;
		++it;
	}
	cout << endl;


	GJG::unordered_map<string , string> s1;
	s1.insert({ "sort", "排序" });
	s1.insert({ "bear", "熊" });

	//值存在充当查找 
	cout << s1["sort"] << endl;
	//值存在充当修改
	s1["bear"] = "容忍, 忍受";

	//充当插入
	s1["pleasure"]; // 用缺省值
	s1["feather"] = "羽毛"; //不用缺省值


	//Print(s1);
}




//测试拷贝构造 , 赋值重载
void Test03()
{
	GJG::unordered_set<int> s;
	//unordered_set<int> s;
	s.insert(1);
	s.insert(1);
	s.insert(1);
	s.insert(2);
	s.insert(3);
	s.insert(4);
	//Print(s);
	cout << "s :" << endl;
	auto it = s.begin();
	while (it != s.end())
	{
		cout << *it << endl;
		++it;
	}
	cout << endl;


	cout << "s1 :" << endl;
	//拷贝构造
	GJG::unordered_set<int> s1(s);

	auto it1 = s1.begin();
	while (it1 != s1.end())
	{
		cout << *it1 << endl;
		++it1;
	}
	cout << endl;


	//赋值重载
	cout << "s2 :" << endl;

	GJG::unordered_set<int> s2;
	s2 = s1;
	
	auto it2 = s2.begin();
	while (it2 != s2.end())
	{
		cout << *it2 << endl;
		++it2;
	}
	cout << endl;
}

int main()
{
	//int a[] = { 9,2,4,1,5,6,7,4,10 };
	//GJG::unordered_set<int> s;
	//GJG::unordered_map<int,int> s;
	//s.insert({ 1,1 });
	//s.insert({ 1,1 });
	//s.insert({1,1});
	//s.insert({2,2});
	//s.insert({3,3});
	//s.insert({4,4});

	////测试普通迭代器
	//auto it = s.begin();
	//while (it != s.end())
	//{
	//	cout << it->first << ":" << it->second << endl;
	//	++it;
	//}
	//cout << endl;

	//const 迭代器
	//Print(s);

	Test01();
	Test02();
	Test03();
	return 0;
}
